package com.gxa.admin.controller;


import com.gxa.admin.pojo.dto.TRoleDto;
import com.gxa.admin.service.RoleService;
import com.gxa.admin.utils.QueryResult;
import com.gxa.core.result.MessageCode;
import com.gxa.core.result.Result;
import com.gxa.core.result.ResultUtils;
import com.gxa.pojo.TResource;
import com.gxa.pojo.TRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <h3>coffee</h3>
 * <p></p>
 *
 * @author : ch
 * @date : 2024-03-21 09:42
 **/
@RestController
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 查询所有角色
     * @param
     * @return List<TRole>
     */
    @PostMapping("/admin/role/showAllRole")
    public Result showAllRole(){

        return ResultUtils.buildSuccess(roleService.showAllRole());
    }
    /**
     * 显示角色列表(分页)
     * @param
     * @return
     */
    @PostMapping("/admin/role/showRole")
    public Result showRole(TRoleDto tRoleDto){
        QueryResult queryResult = this.roleService.showRole(tRoleDto);
        if (queryResult != null) {
//            System.out.println("aaa:"+queryResult);
            return ResultUtils.buildSuccess(queryResult.getCount(), queryResult.getData());
        }
        return ResultUtils.buildFail(MessageCode.UN_KNOW_EXCEPTION);
    }

    @PostMapping("/admin/role/updateRole")
    public Result updateRole(@RequestBody TRole tRole){

        return ResultUtils.buildSuccess(roleService.updateRole(tRole));
    }
    @PostMapping("/admin/role/showRoleResourceVoById")
    public Result showRoleResourceVoById(){

        List<TResource> tResourceList=roleService.showRoleResourceVoById();

        return ResultUtils.buildSuccess(tResourceList);
    }

    @PostMapping("/admin/role/roleAdd")
    public Result roleAdd(@RequestBody TRoleDto tRoleDto){
        System.out.println(tRoleDto);
        return ResultUtils.buildSuccess(roleService.roleAdd(tRoleDto));
    }

    @PostMapping("/admin/role/deleteRole")
    public Result deleteRole(String roleId){

        return ResultUtils.buildSuccess(roleService.deleteRole(roleId));
    }

}
